﻿using UnityEngine;
using Swift;
using UniLua;
using System.Collections.Generic;

// 对应一个 lua 逻辑层的怪物
public class LuaMonster : LuaTable
{
    LuaTable tb;
    public LuaTable LuaTable { get { return tb; } }

    public LuaMonster(LuaState ls, LuaTable m, bool isPlayer, int pos)
        : base(ls)
    {
        tb = m;
        IsPlayer = isPlayer;
        Pos = pos;
    }

    public bool IsPlayer { get; private set; }
    public int Pos { get; private set; }

    public string Name
    {
        get
        {
            return tb.GetStr("name").V.SValue();
        }
    }

    LuaTable Attrs
    {
        get
        {
            return tb.GetStr("attrs").V.HValue();
        }
    }

    public int GetAttrInt(string attr)
    {
        return (int)Attrs.GetStr(attr).V.NValue;
    }

    public LuaTable[] Buffs
    {
        get
        {
            var buffsTb = tb.GetStr("buffs").V.HValue();
            var buffsLst = new List<LuaTable>();
            var n = 1;
            do
            {
                var b = buffsTb.GetInt(n++);
                if (b == null || b.V.TtIsNil())
                    break;

                buffsLst.Add(b.V.HValue());
            } while (true);

            return buffsLst.ToArray();
        }
    }
}